home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / DrawPageLayout.m < prev    next >
Encoding:
Text File  |  1992-04-25  |  2.8 KB  |  104 lines

  1. #import "DrawPageLayout.h"
  2. #import <appkit/Application.h>
  3. #import <appkit/Matrix.h>
  4. #import <appkit/PrintInfo.h>
  5.  
  6. @implementation DrawPageLayout
  7. /*
  8.  * PageLayout is overridden so that the user can set the margins of
  9.  * the page.  This is important in a Draw program where the user
  10.  * typically wants to maximize the drawable area on the page.
  11.  *
  12.  * The accessory view is used to add the additional fields, and
  13.  * pickedUnits: is overridden so that the margin is displayed in the
  14.  * currently selected units.  Note that the accessoryView is set
  15.  * in InterfaceBuilder using the outlet mechanism!
  16.  *
  17.  * This can be used as an example of how to override Application Kit panels.
  18.  */
  19.  
  20. - pickedUnits:sender
  21. /*
  22.  * Called when the user selects different units (e.g. cm or inches).
  23.  * Must update the margin fields.
  24.  */
  25. {
  26.     float old, new;
  27.  
  28.     [self convertOldFactor:&old newFactor:&new];
  29.     [leftMargin setFloatValue:new * [leftMargin floatValue] / old];
  30.     [rightMargin setFloatValue:new * [rightMargin floatValue] / old];
  31.     [topMargin setFloatValue:new * [topMargin floatValue] / old];
  32.     [bottomMargin setFloatValue:new * [bottomMargin floatValue] / old];
  33.  
  34.     return [super pickedUnits:sender];
  35. }
  36.  
  37. - readPrintInfo
  38. /*
  39.  * Sets the margin fields from the Application-wide PrintInfo.
  40.  */
  41. {
  42.     id pi;
  43.     float conversion, dummy;
  44.     NXCoord left, right, top, bottom;
  45.  
  46.     [super readPrintInfo];
  47.     pi = [NXApp printInfo];
  48.     [self convertOldFactor:&conversion newFactor:&dummy];
  49.     [pi getMarginLeft:&left right:&right top:&top bottom:&bottom];
  50.     [leftMargin setFloatValue:left * conversion];
  51.     [rightMargin setFloatValue:right * conversion];
  52.     [topMargin setFloatValue:top * conversion];
  53.     [bottomMargin setFloatValue:bottom * conversion];
  54.  
  55.     return self;
  56. }
  57.  
  58. - writePrintInfo
  59. /*
  60.  * Sets the margin values in the Application-wide PrintInfo from
  61.  * the margin fields in the panel.
  62.  */
  63. {
  64.     id pi;
  65.     float conversion, dummy;
  66.  
  67.     [super writePrintInfo];
  68.     pi = [NXApp printInfo];
  69.     [self convertOldFactor:&conversion newFactor:&dummy];
  70.     if (conversion) {
  71.     [pi setMarginLeft:[leftMargin floatValue] / conversion
  72.             right:[rightMargin floatValue] / conversion
  73.               top:[topMargin floatValue] / conversion
  74.            bottom:[bottomMargin floatValue] / conversion];
  75.     }
  76.  
  77.     return self;
  78. }
  79.  
  80. /* outlet setting methods */
  81.  
  82. - setTopBotForm:anObject
  83. {
  84.     [anObject setTarget:ok];
  85.     [anObject setAction:@selector(performClick:)];
  86.     [anObject setNextText:width];
  87.     topMargin = [anObject findCellWithTag:5];
  88.     bottomMargin = [anObject findCellWithTag:6];
  89.     return self;
  90. }
  91.  
  92. - setSideForm:anObject
  93. {
  94.     [scale setNextText:anObject];
  95.     [anObject setTarget:ok];
  96.     [anObject setAction:@selector(performClick:)];
  97.     leftMargin = [anObject findCellWithTag:3];
  98.     rightMargin = [anObject findCellWithTag:4];
  99.     return self;
  100. }
  101.  
  102. @end
  103.  
  104.